#include "SelectorModel.h"
#include "AssetModel.h"

namespace Xps
{
	SelectorModel::SelectorModel() : QProxyModel()
	{
		root = NULL;
	}

	void SelectorModel::setModel(QAbstractItemModel * model, int mode) 
	{
		QProxyModel::setModel(model);
		AssetModel* tm = (AssetModel*)model;

		if (mode == 0)
			root = tm->questionsRootItem;
		if (mode == 1)
			root = tm->attributesRootItem;
	}

	QVariant SelectorModel::data(const QModelIndex & index, int role ) const
	{
		return root->child(index.row())->data(role);
	}

	Qt::ItemFlags SelectorModel::flags(const QModelIndex & index) const  
	{
		return Qt::ItemFlag::ItemIsSelectable | Qt::ItemFlag::ItemIsEnabled;
	}

	int sizeHintForRow (int row) 
	{
		return 30;	
	}

	int SelectorModel::rowCount(const QModelIndex &parent) const
	{
		if (root != NULL)
		{
			return root->rowCount();
		}
		return 0;
	}


	int SelectorModel::columnCount(const QModelIndex &parent) const
	{
		return 1;
	}

	QModelIndex SelectorModel::parent(const QModelIndex & index) const
	{
		return QModelIndex();
	}

	QModelIndex SelectorModel::index(int row, int column, const QModelIndex &parent) const
	{
		if (!hasIndex(row, column, parent))
			return QModelIndex();

		return createIndex(row, column, root->child(row));
	}
}